package com.stone.persistent.recyclerview.adapter.viewholder;

import android.content.Context;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager2.widget.ViewPager2;

import com.stone.persistent.recyclerview.R;
import com.stone.persistent.recyclerview.adapter.CarouselAdapter;
import com.stone.persistent.recyclerview.widget.CarouselConstraintLayout;
import com.stone.persistent.recyclerview.widget.ViewPagerIndicator;

import org.jetbrains.annotations.NotNull;


public  class CarouselViewHolder extends RecyclerView.ViewHolder {
    private  ViewPager2 viewPager;

    public  void invalidate() {
        viewPager.setCurrentItem(viewPager.getCurrentItem());
    }

    public CarouselViewHolder(@NotNull View itemView, @NotNull Context activity) {
        super(itemView);
        this.viewPager = (ViewPager2)itemView.findViewById(R.id.home_carousel_viewpager2);

        viewPager.setAdapter(new CarouselAdapter(activity));
        viewPager.setCurrentItem(2000);
        ((ViewPagerIndicator)itemView.findViewById(R.id.home_carousel_indicator)).setViewPager2(viewPager, 5);
        CarouselConstraintLayout carouselConstraintLayout = (CarouselConstraintLayout)itemView;
        carouselConstraintLayout.startCarousel(viewPager);
    }
}
